using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Utilities
{
  public static class Geometry
  {
      public static float pi = MathHelper.Pi;

    public static float sin(float x) {return (float)Math.Sin(x);}
    public static float cos(float x) {return (float)Math.Cos(x);}

    public static ArrayList<VertexPositionTexture> sphere_vertices(int w, int h)
    {
        
        //return from i in Enumerable.Range(0, w)
        //       let a = i / (w - 1.0f)
        //       from j in Enumerable.Range(0, h)
        //       let b = j / (h - 1.0f)
        //       let v = new Vector3(sin(b * pi) * cos(a * pi * 2.0f), cos(b * pi), sin(b * pi) * sin(a * pi * 2.0f))
        //       let uv = new Vector2(a, b)
        //       select new VertexPositionTexture(v, uv);
        ArrayList<VertexPositionTexture> tempList = new ArrayList<VertexPositionTexture>();
        for (int i = 0; i < w; i++)
        {
            var a = i / (w - 1.0f);
            for (int j = 0; j < h; j++)
            {
                var b = j / (h - 1.0f);
                var v = new Vector3(sin(b * pi) * cos(a * pi * 2.0f), cos(b * pi), sin(b * pi) * sin(a * pi * 2.0f));
                var uv = new Vector2(a, b);
                tempList.Add(new VertexPositionTexture(v, uv));
            }
        }
        return tempList;
    }

    //let sphere_indices w h =
    //  seq{for i in 0..w-2 do
    //        for j in 0..h-2 do
    //          let A = (i+0) + (j+0) * w |> uint16
    //          let B = (i+1) + (j+0) * w |> uint16
    //          let C = (i+0) + (j+1) * w |> uint16
    //          let D = (i+1) + (j+1) * w |> uint16
    //          yield! [A;B;C;B;D;C]
  }
}
